package com.neusoft.neumooc.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.core.common.BaseService;
import com.neusoft.core.common.exception.ServiceException;
import com.neusoft.neumooc.dao.TemplateDAO;
import com.neusoft.neumooc.vo.TemplateVO;

@Service
@Transactional
public class TemplateServiceImpl extends BaseService implements TemplateService {

    @Autowired
    private TemplateDAO templateDAO;
    
    @Override
    public List<TemplateVO> getAllBuiltinTemplates() throws ServiceException {
        try {
            return templateDAO.getAllBuiltinTemplates();
        } catch (Exception e) {
            log.error("获取内置模板列表失败", e);
            throw new ServiceException("获取内置模板列表失败", e);
        }
    }
    
    @Override
    public List<TemplateVO> getAllCustomTemplates() throws ServiceException {
        try {
            return templateDAO.getAllCustomTemplates();
        } catch (Exception e) {
            log.error("获取自定义模板列表失败", e);
            throw new ServiceException("获取自定义模板列表失败", e);
        }
    }

    @Override
    public TemplateVO getTemplateByFile(String tplFile) throws ServiceException {
        try {
            return templateDAO.getTemplateByFile(tplFile);
        } catch (Exception e) {
            log.error("获取模板失败", e);
            throw new ServiceException("获取模板失败", e);
        }
    }

    @Override
    public boolean updateTemplate(TemplateVO template) throws ServiceException {
        try {
            return templateDAO.updateTemplate(template);
        } catch (Exception e) {
            log.error("更新模板失败", e);
            throw new ServiceException("更新模板失败", e);
        }
    }

    @Override
    public boolean deleteTemplate(String tplFile) throws ServiceException {
        try {
            return templateDAO.deleteTemplate(tplFile);
        } catch (Exception e) {
            log.error("删除模板失败", e);
            throw new ServiceException("删除模板失败", e);
        }
    }
    
    @Override
    public boolean addTemplate(TemplateVO template) throws ServiceException {
        try {
            return templateDAO.addTemplate(template);
        } catch (Exception e) {
            log.error("添加模板失败", e);
            throw new ServiceException("添加模板失败", e);
        }
    }

    @Override
    public List<TemplateVO> getTemplatesByType(String tplType) throws ServiceException {
        try {
            return templateDAO.getTemplatesByType(tplType);
        } catch (Exception e) {
            log.error("获取模板列表失败", e);
            throw new ServiceException("获取模板列表失败", e);
        }
    }
} 